#include "BlazeEngineLibrarySystem.h"


BeLibrarySystem::BeLibrarySystem()
{

}

BeLibrarySystem::~BeLibrarySystem()
{

}

BeLibrary* BeLibrarySystem::Load(std::string strFileName)
{
	LibraryList::iterator it = m_LibList.find(strFileName);

	if (it != m_LibList.end())
	{
		return it->second;
	}
	else
	{
		BeLibrary* pLibrary = new BeLibrary(strFileName);

		pLibrary->Load();        
		m_LibList[strFileName] = pLibrary;

		return pLibrary;
	}
}

void BeLibrarySystem::Unload(BeLibrary* pLibrary)
{
	LibraryList::iterator it = m_LibList.find(pLibrary->GetFileName());

	if (it != m_LibList.end())
	{
		m_LibList.erase(it);
	}

	pLibrary->Unload();
	
	delete pLibrary;
}

void BeLibrarySystem::UnloadAll()
{
	for (LibraryList::iterator it = m_LibList.begin(); it != m_LibList.end(); it++)
	{
		BeLibrary* pLibrary = it->second;
		
		pLibrary->Unload();

		delete pLibrary;
	}

	m_LibList.clear();

}
